<!DOCTYPE html>
<html>
	<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实习指导老师</title>
    <meta name="description" content="老师指导的毕业设计学生">
    <meta name="keywords" content="实习指导老师,实习指导老师评语,实习指导教师职责,实习指导教师意见,实习网">
    <link href="{$Think.const.CSS_URL}bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="{$Think.const.CSS_URL}style.css">
    <script src="{$Think.const.JS_URL}jquery-1.12.3.min.js"></script>    
	<script src="{$Think.const.JS_URL}bootstrap.min.js"></script>
	<script src="{$Think.const.JS_URL}jquery.validate.min.js"></script>
	<style>
		tr td{
			text-align:center;
		}
	</style>
	{php}
	   use app\model\SchoolMajor;
	{/php}
	</head>
	<body>
		<div class="container-fluid">
		   <div class="row">
			   <div class="col-md-12">
             
				   <div class="alert alert-success" role="alert">
					<p>老师管理：参与毕业设计的老师。注：专业负责人可以对本专业的课题审批 
					<a href="/down/bishe/teacher.rar" class="alert-link"><button class="btn btn-primary" >下载教师EXCEL样表</button></a>
					<a href="#" class="alert-link"><button class="btn btn-primary" onclick="imp()">+导入EXCEL教师列表</button></a>

					<a href="#" class="alert-link"><button class="btn btn-primary" onclick="$('#add').modal('show')">+手工添加教师</button></a>
					<a href="#" class="alert-link"><button class="btn btn-primary" onclick="$('#addteacher').modal('show')">+从教师库添加</button></a>
					<a class="btn btn-default" href="{:url('shixi/exportTeacherData')}" role="button">导出教师列表</a>
					</p>						 
				   </div>
				   
				   {empty name="teacher"}
					  暂无教师
				   {else /}
					<table class="table table-bordered">
						<tr>
						  <td >#ID</td>
						  <td >工号</td>
						  <td >姓名</td>
						  <td >手机</td>
						  <td >角色</td>
						  <td >所属专业</td>
				          <td >最多指导学生数</td>
						  <td >操作</td>
						</tr>
						{volist name="teacher" id="data" key="k"}
						<tr>
						  <td >{$k}</td>
						  <td >{$data.username}</td>
						  <td >{$data.truename}</td>
						  <td >{$data.mobile}</td>
						  <td >
							{switch data.role}
								{case 1}专业负责人{/case}
								{case 2}督查{/case}
								{default /}无
							{/switch}					  					
						  </td>
						  <td >
							  {php}$major=new SchoolMajor();echo $major->getproname($data['majorid']);{/php}
		
						  </td>
						  <td >{$data.student}</td>
						  <td >
							  <a href="#" onclick="del({$data.id})"> 删除 </a> 
							  <a href="#" onclick="edit({$data.id})" style="margin:0px 10px;"> 编辑</a>
							  <a href="#" onclick="set({$data.id})" style="margin:0px 10px;"> 设为角色</a>
							  <a href="#" onclick="setpro({$data.id})" style="margin:0px 10px;"> 设所属专业</a>
                              <a href="#" onclick="setnum({$data.id})" style="margin:0px 10px;">修改指导人数</a>
							  
						  </td>
						</tr>
						{/volist}
					</table>
					   {$teacher|raw}
					{/empty}



		        </div>
		  </div>
		</div>
	
	
	
	<!--设置指导人数-->
	<div class="modal fade" tabindex="-1" role="dialog" id="zhidaonum">
	  <div class="modal-dialog" role="document" style="z-index: 11111;">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">设置老师指导学生人数</h4>
	      </div>
	      <div class="modal-body">
			<form  id="zhidaoform">
			<label class="radio-inline">
			  指导人数<input type="number" name="num1" min=0> 
			</label>
			<input type="hidden" name="id" id="id4">
			
			<button type="button" class="btn btn-default" onclick="setsave()">设置</button>
			</form>
			
	      </div>
	          
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->		
	
		
<script>
		function setnum(id){
			$('#id4').val(id)		
		    $('#zhidaonum').modal('show')			
		  }
</script>	
	  
<script>		
		function setsave(){
		   $.ajax({
		       type:"post",
		       url:"{:url('shixi/grade_teachersetNum')}",
		       dataType:"json",
		       data:$('#zhidaoform').serialize(),
		       success:function(data){  
		        alert(data);
				location.reload();             
		       }
		       });     			
		  }	
			
	    //导出  
		function export1(){
		   $.ajax({
		       type:"post",
		       url:"{:url('shixi/exportTeacherData')}",
		       dataType:"json",
		       data:{},
		       success:function(data){  
		        alert(data);       
		       }
		       });     			
		  }	  
			  
</script>
		
		
		
		<!--添加-->
		<div class="modal fade" tabindex="-1" role="dialog" id="add">
		  <div class="modal-dialog" role="document" style="z-index: 11111;">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title">添加教师</h4>
		      </div>
		      <div class="modal-body">
		      <form class="form-horizontal" id="addform">
					<div class="form-group">
					<label for="area" class="col-xs-2 col-sm-2 col-md-2 control-label">老师工号</label>
					<div class="col-xs-10 col-sm-10 col-md-10">
				<input type="text" class="form-control" id="username"  name="username"  placeholder="账号是老师工号"  data-msg-required="<span style='color:red;'>手机的格式不正确</span>" >
		
					</div>
					</div> 
						
					
					<div class="form-group">
					<label for="depart" class="col-xs-2 col-sm-2 col-md-2 control-label">密码</label>
					<div class="col-xs-10 col-sm-10 col-md-10">
                      <input type="text" name="password" class="form-control" id="password" placeholder="密码可以默认设置为123456">
					</div>
					</div>
					
		
					  <div class="form-group">
						<label for="begintime" class="col-sm-2 control-label">姓名</label>
						<div class="col-sm-10">
		                <input type="text" name="truename" id="truename" class="form-control" placeholder="老师真实姓名">
						</div>
					  </div>
					  
					  
				<div class="form-group">
					<label for="mobile" class="col-sm-2 control-label">手机号码</label>
					<div class="col-sm-10">
				  <input type="text" name="mobile" id="mobile" class="form-control" placeholder="手机号码，方便联系">
					</div>
				</div>	  
					  
					  
							  
					 	<input type="hidden"  name="user_class"	value=1>
						<input type="hidden"  name="regclass"	value=1>	
					  <div class="form-group">
						<div class="col-sm-offset-4 col-sm-10">
						  <button type="button" class="btn btn-default" onclick="add()"> 添加</button>
						</div>
					  </div>
					</form>
		      </div>
		
		    </div><!-- /.modal-content -->
		  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->

		
	<script>
		//导入 
		function  imp(){
            alert('导入前，先在左边下载"教师excel样表"，按样表格式组织教师信息，否则，可能输入不成功！')
			$('#import').modal('show')
		}
		
		$().ready(function() {
		 $("#addform").validate();
		 });
		
		jQuery.validator.addMethod("mobile", function(value, element) {       
		  var length = value.length;   
		  var mobile = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;   
		  return this.optional(element) || (length == 11 && mobile.test(value));       
		  }, "<span style='color:red;'>请正确填写您的手机号码</span>");
		  
		  
		function add(){
			username=$('#username').val();
			truename=$('#truename').val();
			password=$('#password').val();
			user_school=$('#user_school').val();
			mobile=$('#mobile').val();
			if(username.length==0){
				alert('老师工号不能为空');
				return 
			}
			if(password.length==0){
				alert('密码不能为空');
				return 
			}
			if(truename.length==0){
				alert('姓名不能为空');
				return 
			}
			if(mobile==""){
				alert('手机号码不能为空');
				return 
			}
			if(user_school==0){
				alert('学校不能为空');
				return 
			}

			else{
		   $.ajax({
		       type:"get",
		       url:"{:url('shixi/grade_teacheradd')}",
		       dataType:"text",
		       data:$('#addform').serialize(),
		       success:function(data){  
		        alert(data);
				location.reload();             
		       }
		       });     		
			}
		}  
	</script>
		
		
	<!--修改-->
	<div class="modal fade" tabindex="-1" role="dialog" id="editwin">
	  <div class="modal-dialog" role="document" style="z-index: 11111;">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">修改教师</h4>
	      </div>
	      <div class="modal-body">
	      <form class="form-horizontal" id="editform">
				<div class="form-group">
				<label for="area" class="col-xs-2 col-sm-2 col-md-2 control-label">老师工号</label>
				<div class="col-xs-10 col-sm-10 col-md-10">
			<input type="text" class="form-control" id="username1"  name="username"  placeholder="老师工号是登录账号">
	        <input type="hidden" class="form-control" id="username2"  name="username2"  placeholder="老师工号是登录账号">
	
				</div>
				</div> 
					
				<input type="hidden" name="id" id="editid">
				
<!-- 				<div class="form-group">
				<label for="depart" class="col-xs-2 col-sm-2 col-md-2 control-label">密码</label>
				<div class="col-xs-10 col-sm-10 col-md-10">
	              <input type="text" name="password" class="form-control" id="password1" placeholder="密码可以默认设置为123456">
				</div>
				</div> -->
				
	
				  <div class="form-group">
					<label for="begintime" class="col-sm-2 control-label">姓名</label>
					<div class="col-sm-10">
	                <input type="text" name="truename" id="truename1" class="form-control" >
					</div>
				  </div>
				  
				  
				  <div class="form-group">
				  	<label for="mobile" class="col-sm-2 control-label">手机号码</label>
				  	<div class="col-sm-10">
				    <input type="text" name="mobile" id="mobile1" class="form-control" placeholder="手机号码，方便联系">
				  	</div>
				  </div>	  
				  	  
				  	  
				 
			  
				 	<input type="hidden"  name="user_class"	value=1>
					<input type="hidden"  name="regclass"	value=1>	
				  <div class="form-group">
					<div class="col-sm-offset-4 col-sm-10">
					  <button type="button" class="btn btn-default" onclick="save()"> 修改</button>
					</div>
				  </div>
				</form>
	      </div>
	
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
	
	<script>
	  $(document).ready(function(){
	     $('#province1').change(function(){
	    	$opt = "<option value='0'>-请选择城市-</option>";
	        $.ajax({
	            type:"get",
	            url:"{:url('region/getcity')}",
	            data:'id='+$('#province1').val(),
	            dataType:"json",
	            success:function(data){  
	            var data = eval(data); 
			   for (var i = 0; i < data.length; i++) { 
				var id = data[i].id;  
	            var name =data[i].name;   
			    $opt += "<option value="+id+">"+name+"</option>";
			   } 
	            $('#city1').html($opt);    
	            }
	            });
	    });
	  });
	    
	</script> 
	 
	 
	 <!--AJAX取得大学-->
	 <script>
	  $(document).ready(function(){
	     $('#city1').change(function(){
	    	$opt = "<option value='0'>-请选择大学-</option>";
	        $.ajax({
	            type:"get",
	            url:"{:url('school/getschool')}",
	            data:'id='+$('#city1').val(),
	            dataType:"json",
	            success:function(data){  
	            var data = eval(data); 
			   for (var i = 0; i < data.length; i++) { 
				      var id = data[i].id;  
	            var name =data[i].name;   
			    $opt += "<option value="+id+">"+name+"</option>";
			      } 
	            $('#user_school1').html($opt);    
	            }
	            });
	    });
	  });
	    
	</script> 
	 
	<!--AJAX取得院系-->
	 <script>
	  $(document).ready(function(){
	     $('#user_school1').change(function(){
	    	$opt = "<option value='0'>-请选择院系-</option>";
	        $.ajax({
	            type:"get",
	            url:"{:url('school/getxi')}",
	            data:'id='+$('#user_school1').val(),
	            dataType:"json",
	            success:function(data){  
	            var data = eval(data); 
			   for (var i = 0; i < data.length; i++) { 
				      var id = data[i].xi_id;  
	            var name =data[i].xi_name;   
			    $opt += "<option value="+id+">"+name+"</option>";
			      } 
	            $('#user_xi1').html($opt);    
	            }
	            });
	    });
	  });
	    
	</script>  
	
	
		
	<script>
	
	     function edit(id){
		    
	        $.ajax({
	            type:"get",
	            url:"{:url('shixi/grade_teacheredit')}",
	            dataType:"json",
	            data:'id='+id,
	            success:function(data){  
				
	              data=eval("("+data+")");
				     
			          $('#username1').val(data['username']);
				      $('#username2').val(data['username']);
					  $('#truename1').val(data['truename']);
					  $('#mobile1').val(data['mobile']);
						  
					  $('#editid').val(data['uid']);	
	            }
	            });
		    $('#editwin').modal('show')
	     	}
	 	
	
		 
	     function del(id){
		   if(confirm('确定删除吗?')){
	        $.ajax({
	            type:"get",
	            url:"{:url('shixi/grade_teacherdel')}",
	            dataType:"text",
	            data:'id='+id,
	            success:function(data){  
	             alert(data);
			    location.reload();             
	            }
	            });     		
	     	}
	 	   }
	
	
	     function save(){
	        username=$('#username1').val();
			username2=$('#username2').val();
	        truename=$('#truename1').val();
	        password=$('#password1').val();
			user_school=$('#user_school1').val();
			mobile=$('#mobile1').val();
			
			// //工号是否存在
			// if(username!=username2){
				
			//   $.post("{:url('user/checkuser')}",
			//   {
			//     username:$('#username1').val(),
			//   },
			//   function(data){
			// 	 if(data){
			// 		alert("工号已被占用")	
			// 		return  
			// 	 }
			//   });
			// }
			
			
	        if(username.length==0){
	        	alert('工号不能为空');
	        	return 
	        }
			
	        if(truename.length==0){
	        	alert('姓名不能为空');
	        	return 
	        }
			
	        if(password.length==0){
	        	alert('密码不能为空');
	        	return 
	        }
			if(mobile.length==0){
				alert('手机不能为空');
				return 
			}
			if(user_school==0){
				alert('学校不能为空');
				return 
			}			
	        else{
	        $.ajax({
	            type:"get",
	            url:"{:url('shixi/grade_teachersave')}",
	            dataType:"text",
	            data:$('#editform').serialize(),
	            success:function(data){  
	             alert(data);
			     location.reload();             
	            }
	            });     		
	     	}
	     }  	 
	
	
	</script> 	
	
	
	<!--导入数据-->
	<div class="modal fade" tabindex="-1" role="dialog" id="import">
	  <div class="modal-dialog" role="document" style="z-index: 11111;">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">导入教师</h4>
	      </div>
	      <div class="modal-body">
			<form action="{:url('shixi/impTeacherExcel')}" enctype="multipart/form-data" method="post">
			<input type="file" name="file" accept=".xls,.xlsx"/> <br> 
			<input type="submit" value="上传" /> 
			</form> 
	      </div>
	
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->		
	
	<!--设置角色-->
	<div class="modal fade" tabindex="-1" role="dialog" id="role">
	  <div class="modal-dialog" role="document" style="z-index: 11111;">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">设置角色</h4>
	      </div>
	      <div class="modal-body">
			<form  id="roleform">
			<label class="radio-inline">
			  <input type="radio" name="role"  value="0" checked="checked" onclick="testrole(0)"> 无
			</label>
			<label class="radio-inline">
			  <input type="radio" name="role"  value="1" onclick="testrole(1)"> 专业负责人
			</label>
			<div style="display:none;" id="majorshow">负责专业
			<select name="majorid" style="width:80px;">
			  {volist name="majors" id="data"}
				<option value="{$data.pro_id}">{$data.pro_name}</option>
			  {/volist}
			</select>
			</div>
			<label class="radio-inline">
			  <input type="radio" name="role"  value="2" onclick="testrole(2)"> 督查
			</label>

			<input type="hidden" name="id" id="id2">
			</form>
			<button type="button" onclick="set1()">设置</button>
	      </div>
	          
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->		
	
	
	
	
	
	
	
	
	<script>
		//角色选中状态
		function  testrole(id){
			if(id==0){
			  $('#majorshow').hide()
			}
			if(id==1){
			  $('#majorshow').show()
			}
			if(id==2){
			  $('#majorshow').hide()
			}
		}
		
		
		function set(id){
			$('#id2').val(id)
		    $('#role').modal('show')			
		  }
		  
		
		function set1(id){
		
		   $.ajax({
		       type:"post",
		       url:"{:url('shixi/grade_teacherset')}",
		       dataType:"text",
		       data:$('#roleform').serialize(),
		       success:function(data){  
		        alert(data);
				location.reload();             
		       }
		       });     			
		  }
	
		
	</script>
	
	
	<!--设置所属专业-->
	<div class="modal fade" tabindex="-1" role="dialog" id="rolepro">
	  <div class="modal-dialog" role="document" style="z-index: 11111;">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">设老师所属专业</h4>
	      </div>
	      <div class="modal-body">
			<form  id="roleproform" class="form-horizontal">
			  <div class="form-group">
			    <select name="majorid"  class="form-control">
			      {volist name="majors" id="data"}
			    	<option value="{$data.pro_id}">{$data.pro_name}</option>
			      {/volist}
			    </select>
			  </div>

			<input type="hidden" name="id"  id="id5">
			</form>
			<button type="button" onclick="set3()">设置</button>
	      </div>
	          
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->	
	
	<script>

	
		function setpro(id){
			$('#id5').val(id)
		    $('#rolepro').modal('show')			
		  }
		  
		
		function set3(){
		
		   $.ajax({
		       type:"post",
		       url:"{:url('shixi/grade_teachersetpro')}",
		       dataType:"text",
		       data:$('#roleproform').serialize(),
		       success:function(data){  
		        alert(data);
				location.reload();             
		       }
		       });     			
		  }
	
		
	</script>
	
	
	<!--从教师库中添加教师-->
	<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" id="addteacher">
	  <div class="modal-dialog modal-lg" role="document" style="z-index: 11111;">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">添加指导教师
			<select name="xiid"  class="form-control" style="width:250px;float:right;margin-right:20px;" onchange="getTeacher(this.value)">
			  {volist name="xis" id="data"}
				<option value="{$data.xi_id}">{$data.xi_name}</option>
			  {/volist}
			</select>
			</h4>
	      </div>
	      <div class="modal-body">
              <div id="teacherlist" style="height:500px;overflow: auto;"></div>   
			<center><button type="button" onclick="teacheradd()">添加</button></center>
	      </div>
	          
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->	
	
	<script>
		
	function  getTeacher(xiid){
		txt="<table class='table table-bordered'><tr><td>#ID</td><td>工号</td><td>姓名</td><td>性别</td><td><input type='checkbox' name='sel' onclick='selectall()'>选择</td></tr>"
		$.ajax({
		    type:"get",
		    url:"{:url('user/getTeachersByDepart')}",
		    dataType:"json",
		    data:{xi:xiid},
		    success:function(data){  
		     data=eval(data);
			 for(i=0;i<data.length;i++){
			   txt+="<tr><td>"+(i+1)+"</td><td>"+data[i]['username']+"</td><td>"+data[i]['truename']+"</td><td>"+data[i]['sex']+"</td><td><input name='uid' type='checkbox' value='"+data[i]['uid']+"'></td></tr>"	 
			 }
			txt+="</table>"
			$('#teacherlist').html(txt)
		    }
		    });     		
		}
					
		//添加教师到指导组			
		function teacheradd(){
		
			var user = [];
			document.querySelectorAll("body input:checked").forEach((e)=>{
				if(e.checked){
					user.push(e.value);
				}
			});
			
			if(user.length==0){
			   alert('请选择老师');
			   return
			}
			else{
				
		   $.ajax({
		       type:"get",
		       url:"{:url('shixi/teacherInGrade')}",
		       dataType:"json",
		       data:{user:user.toString()},
		       success:function(data){  
		        alert("操作成功"); 
				location.reload()
		       }
		       });     		
			}
		}  
					
					
		function selectall(){
			var inputs =  document.getElementsByName("uid");
		       sel = document.getElementsByName('sel');
			if(sel[0].checked){
				for(var i = 0;i<inputs.length;i++){
				   inputs[i].checked = true;
				}
			}
			else{
				for(var i = 0;i<inputs.length;i++){
				   inputs[i].checked = false;
				}
			  }
		}						
					
	</script>
	
	
		
	</body>
</html>
